<template>
  <div class="slave_wnd">
    <div class="wnd">
      <div style="overflow: hidden">
        <el-button
          type="text"
          style="float: right; padding: 0px"
          @click="close()"
          ><i class="el-icon-close" style="font-size: 30px"></i
        ></el-button>
      </div>
      <el-divider></el-divider>
      <div class="block">
        <span>客户机: {{ slave_name }}</span>
      </div>
      <div class="block">
        <span style="line-height: 40px">音量: </span>
        <el-slider class="vol-slider" v-model="master_volume"></el-slider>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "SlaveItemWnd",
  props: {
    slave_name: String,
    slave_uuid: String,
  },
  data: function () {
    return {
      timeout: null,
      master_volume: 0,
    };
  },
  methods: {
    close() {
      this.$emit("wnd-close");
    },
  },
  watch: {
    master_volume(newLevel) {
      clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        console.log("send set volume...");
        this.$axios
          .get(`slave/${this.slave_uuid}/volume/${newLevel}`)
          .then((resp) => {
            console.log(resp);
          });
      }, 100);
      console.log("volume changed " + newLevel);
    },
  },
};
</script>

<style>
.slave_wnd {
  width: 100%;
  height: 100%;
  background-color: #ffffff;
  position: absolute;
  top: 0px;
  left: 0px;
  text-align: left;
}

.block {
  padding: 16px;
}

.vol-slider {
  float: right;
  width: 80%;
}

.wnd {
  padding: 20px;
}
</style>
